var a = require("../../utils/api.js"), t = getApp();

Page({
    data: {
        rankingNav: [],
        curOrderStatus: 0,
        curCode: 0,
        rkList: [],
        showLoding: !1
    },
    onLoad: function(e) {
        var o = this, n = wx.getSystemInfoSync();
        if (o.setData({
            windowHeight: n.windowHeight - Math.round(n.windowWidth / 375 * 55)
        }), wx.setNavigationBarColor({
            frontColor: wx.getStorageSync("basic").topcolor,
            backgroundColor: wx.getStorageSync("basic").topbg
        }), "captain" == e.resource) wx.setNavigationBarTitle({
            title: "团长排行"
        }), o.setData({
            resource: "captain",
            showNo: !1
        }), a.GetTeamRankSet({
            openid: t.globalData.openid
        }).then(function(a) {
            console.log(a), 0 == a.errno ? o.setData({
                rankingNav: a.data
            }) : o.setData({
                rankingNav: [ {
                    status: 0,
                    name: "日榜"
                }, {
                    status: 10,
                    name: "周榜"
                }, {
                    status: 20,
                    name: "月榜"
                }, {
                    status: 30,
                    name: "年榜"
                } ]
            });
            var e = o.data.rankingNav, n = "";
            for (var s in e) {
                n = e[s];
                break;
            }
            var i = {
                openid: t.globalData.openid,
                status: n.status
            };
            o.getinfo(i), console.log(o.data.rkList);
        }); else if ("member" == e.resource) {
            wx.setNavigationBarTitle({
                title: "团员排行"
            });
            var s = {
                openid: t.globalData.openid
            };
            o.getMemberinfo(s), o.setData({
                rankingNav: [ {
                    status: 0,
                    name: "团员排行榜"
                } ]
            });
        }
    },
    rankingTap: function(a) {
        console.log(a);
        var e, o = this, n = a.currentTarget.dataset.id, s = o.data.rankingNav;
        o.setData({
            showLoding: !1
        });
        for (var i = 0; i < s.length; i++) n == s[i].status && (e = i);
        if (o.setData({
            curOrderStatus: n,
            curCode: e,
            click: !0
        }), o.setData({
            rkList: ""
        }), console.log(e), "captain" == o.data.resource) {
            r = {
                openid: t.globalData.openid,
                status: s[e].status
            };
            o.getinfo(r);
        } else if ("member" == o.data.resource) {
            var r = {
                openid: t.globalData.openid,
                status: s[e].status
            };
            o.getMemberinfo(r);
        }
    },
    onBottom: function(a) {},
    bindChange: function(a) {
        var e = this;
        if (e.setData({
            showLoding: !1
        }), e.data.click) return e.setData({
            click: !1,
            showLoding: !0
        }), !1;
        console.log(a);
        var o = a.detail.current, n = e.data.rankingNav;
        console.log(o);
        for (var s, i = 0; i < n.length; i++) o == i && (s = n[i].status);
        if (console.log(s), e.setData({
            curOrderStatus: s
        }), e.setData({
            rkList: ""
        }), "captain" == e.data.resource) {
            r = {
                openid: t.globalData.openid,
                status: s
            };
            e.getinfo(r);
        } else if ("member" == e.data.resource) {
            var r = {
                openid: t.globalData.openid,
                status: s
            };
            e.getMemberinfo(r);
        }
    },
    getinfo: function(t) {
        var e = this;
        a.GetTeamRank(t).then(function(a) {
            if (0 == a.errno) {
                if (0 == a.data.length) t = !0; else var t = !1;
                e.setData({
                    rkList: a.data,
                    showNo: t
                });
            } else e.setData({
                showNo: !0
            });
            e.setData({
                showLoding: !0
            });
        });
    },
    getMemberinfo: function(t) {
        var e = this;
        a.headMemberRank(t).then(function(a) {
            if (console.log(a), 0 == a.errno) {
                if (0 == a.data.length) t = !0; else var t = !1;
                e.setData({
                    rkList: a.data,
                    resource: "member",
                    showNo: t
                });
            } else e.setData({
                showNo: !0
            });
            e.setData({
                showLoding: !0
            });
        });
    }
});